<template>
  <div>
    <BlogHeader :active-index="'3'"></BlogHeader>
    <div class="main">
      <div class="infinite-list-wrapper" style="overflow:auto">

        <ul v-for="i in questions">
          <li key="i._id">
            <div class="el-table-filter__list-item">
              <router-link class="title" :to="{name: 'QuestionDetail', params: {id: i._id}}">
                <div style="text-align: center">
                  第{{i.id}}题：{{i.title}}
                </div>
              </router-link>
            </div>
            <el-divider></el-divider>
          </li>
        </ul>

        <p v-if="loading"><el-skeleton /></p>
        <p v-if="noMore">没有更多了</p>

      </div>
  </div>

  </div>



</template>

<script>
import {getBlogs} from "../api/api";
import BlogHeader from "../components/BlogHeader";
export default {
  name: "QuestionList",
  components: {BlogHeader},
  data () {
    return {

      questions: [],
      loading: false,
      url: '/api/question/page',
      curPage: 0,
    }
  },

  mounted() {
    this.loadBooks()
  },

  computed: {
    noMore () {
      return !this.nextUrl
    },
    disabled () {
      return this.loading || this.noMore
    }
  },

  methods: {
    loadBooks() {
      getBlogs(this.url + this.curPage).then(response => {
        const data = response.data.data
        if(data) {
          this.questions = this.questions.concat(data)
          this.curPage ++
        }
        else {
          this.url = null
        }
      })
    },

    load () {
      this.loading = true
      setTimeout(() => {
        if(this.url != null){
          this.loadBooks()
        }
        this.loading = false
      }, 2000)
    }

  },

}
</script>

<style scoped>

.main {

  margin-left: 10em;
  margin-right: 10em;
}

.title {
  color: #121212;
  text-align: center;
  text-decoration: none;
}

ul {
  margin: 0;
  padding-inline-start: 0;
}

p {
  text-align: center;
}







</style>
